const pathResolver = require('../config/path_resolver');
const pageHelper = require('../../config/path_import.js').pageHelper;
const ProjectBiz = require('../../../comm/biz/project_biz.js');
const FlowBiz = require('../../../biz/flow_biz.js');
const behavior = require('../../../../../comm/behavior/flow_index_bh.js');

Page({
	behaviors: [behavior],

	/**
	 * 页面的初始数据
	 */
	data: {
		isLoad: false,
		oprt: 'flow_history',

		showAdmin: false, // 不显示后台按钮 

		title: '审批历史',
		currentSet: {
			cate: '',
			type: '',
			search: '',
			sortType: 'sort',
			sortVal: 'desc',

			page: 1,
			size: 20,
			isTotal: true,
			oldTotal: 0,
			total: 0,
			totalPage: 0,
			isFull: false,

			path: 'flow/history',
			status: '',
			showAdmin: false,
		},
		list: []
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		ProjectBiz.initPage(this);

		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		this._init();
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		// 每次显示页面时强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	_init: function (e) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		let currentSet = this.data.currentSet;
		let options = {
			title: '审批历史'
		}
		let title = options.title;
		this.setData({
			title,
			currentSet,
		})
		this.getList();
	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		this.setData({
			'currentSet.page': 1
		}, () => {
			this.getList(true);
		})
	},

	getList: function (isPull) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		behavior.getList.call(this, isPull);
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		behavior.onReachBottom.call(this);
	},

	url: function (e) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		pageHelper.url(e, this);
	},

	bindItemTap: async function (e) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		behavior.bindItemTap.call(this, e);
	},

	bindCancelTap: function (e) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		behavior.bindCancelTap.call(this, e);
	},

	bindStatusTap: function (e) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		behavior.bindStatusTap.call(this, e);
	},

	bindSortTap: function (e) {
		// 强制设置登录状态
		FlowBiz.forceSetLoginState(this, 'flow_history');

		behavior.bindSortTap.call(this, e);
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
}) 